package org.schat;

import java.io.IOException;
import java.net.Socket;
/**
 * @Description 客户端连接对象
 * @Author lsh
 **/
public class ClientDomain {
	private String id;
	private String ip;
	private String port;
	private String clientName;
	private Socket socket;
	//在线离线
	private int state;
    //授权情况  -999 权限验证失败。-1 默认状态。2授权成功。
	private int authorization = -1;
	private long lastAcceptTime;
	
	public ClientDomain(String id,String clientName,Socket socket,int state,long lastAcceptTime){
		this.id=id;
		this.clientName=clientName;
		this.socket=socket;
		this.state=state;
		this.lastAcceptTime=lastAcceptTime;
	}

	//关闭socket
	public void closeSocket(){
	    if(socket != null){
	        if(!socket.isClosed()){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public String getClientInfo(){
	    return this.ip+":"+this.getPort();
    }

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Socket getSocket() {
		return socket;
	}

	public void setSocket(Socket socket) {
		this.socket = socket;
	}

	public int getState() {
		return state;
	}

    public int getAuthorization() {
        return authorization;
    }

    public void setAuthorization(int authorization) {
        this.authorization = authorization;
    }

    public void setState(int state) {
		this.state = state;
	}

	public long getLastAcceptTime() {
		return lastAcceptTime;
	}

	public void setLastAcceptTime(long lastAcceptTime) {
		this.lastAcceptTime = lastAcceptTime;
	}


    public String getClientName() {
        return clientName;
    }

    public void setClientName(String clientName) {
        this.clientName = clientName;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }
}
